//
//  Get_Handle_GetUnHandleList_Task.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-5-28.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "Get_Handle_GetUnHandleList_Task.h"
#import "WebServiceHelper.h"
#import "StringUtil.h"
#import "HandleModel.h"
#import "GDataXMLNode.h"

@implementation Get_Handle_GetUnHandleList_Task

-(void)execute
{
    NSString *ValidateData = [self.params objectForKey:@"ValidateData"];
    NSString *url = [self.params objectForKey:@"url"];
    NSString *wsNamespace = [self.params objectForKey:@"namespace"];
    NSString *userguid = [self.params objectForKey:@"userguid"];
    NSString *pagesize = [self.params objectForKey:@"pagesize"];
    NSString *keyword = [self.params objectForKey:@"keyword"];
    NSString *HandleType = [self.params objectForKey:@"HandleType"];
    NSString *CurrentPageIndex = [self.params objectForKey:@"CurrentPageIndex"];
    WebServiceHelper *webserviceHelper = [[WebServiceHelper alloc]initWebServiceWithUrl:url wsNamespace:wsNamespace method:@"Handle_GetUnHandleList"];
    NSString *ParasXml = @"<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><UserGuid>%@</UserGuid><KeyWord>%@</KeyWord><HandleType>%@</HandleType><CurrentPageIndex>%@</CurrentPageIndex><PageSize>%@</PageSize></paras>";
    ParasXml = [NSString stringWithFormat:ParasXml,userguid,keyword,HandleType,CurrentPageIndex,pagesize];
    ParasXml = [StringUtil filterXmlString:ParasXml];
    [webserviceHelper addParameterForString:@"ValidateData" value:ValidateData];
    [webserviceHelper addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs = webserviceHelper.start;
    [self sendDataRefreshUI:bs];
}

+(NSMutableArray *)getListArray:(NSString *)_xml
{
    _xml = [StringUtil getXMLFormatedAttributeIncludeTag:_xml :@"HandleList"];
    
    GDataXMLDocument *doc = [[[GDataXMLDocument alloc] initWithXMLString:_xml  options:0 error:nil]autorelease];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"Handle"];
    NSMutableArray *listmp = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays)
    {
        HandleModel *m = [[HandleModel alloc]init];
        GDataXMLElement *MessageItemGuid = [[arr elementsForName:@"MessageItemGuid"] objectAtIndex:0];
        m.MessageItemGuid = [MessageItemGuid stringValue];
        
        GDataXMLElement *Title = [[arr elementsForName:@"Title"] objectAtIndex:0];
        m.Title = [Title stringValue];
        
        GDataXMLElement *ArchiveNo = [[arr elementsForName:@"ArchiveNo"] objectAtIndex:0];
        m.ArchiveNo = [ArchiveNo stringValue];
        
        GDataXMLElement *FromDispName = [[arr elementsForName:@"FromDispName"] objectAtIndex:0];
        m.FromDispName = [FromDispName stringValue];
        
        GDataXMLElement *GenerateDate = [[arr elementsForName:@"GenerateDate"] objectAtIndex:0];
        m.GenerateDate = [GenerateDate stringValue];
        
        GDataXMLElement *ClientIdentifier = [[arr elementsForName:@"ClientIdentifier"] objectAtIndex:0];
        m.ClientIdentifier = [ClientIdentifier stringValue];
        
        GDataXMLElement *CanHanle = [[arr elementsForName:@"CanHanle"] objectAtIndex:0];
        m.CanHanle = [CanHanle stringValue];
        
        GDataXMLElement *FileType = [[arr elementsForName:@"FileType"] objectAtIndex:0];
        m.FileType = [FileType stringValue];
        
        [listmp addObject:m];
        [m release];
    }
    
    return [listmp autorelease];
}

@end
